import React, { useState, useEffect, useImperativeHandle } from 'react';

function A(props, ref) {
  const [count, setCount] = useState(0);
  useImperativeHandle(ref, () => {
    return {
      aa: 'bao',
      add() {
        setCount(count + 1);
        return count; // 将值 返回给 父组件
      },
    };
  });

  return (
    <div>
      函数 子组件 count : {count}
      <button onClick={() => setCount(count + 1)}> count ++ </button>
      <hr></hr>
    </div>
  );
}
export default React.forwardRef(A); // 子组件 一定要使用 forwardRef 包裹
